package controller

import (
	"context"
	"github.com/gogf/gf/v2/util/gconv"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var Department = cDepartment{}

type cDepartment struct{}

// AddDepartment  新增部门
func (h *cDepartment) AddDepartment(ctx context.Context, req *api.AddDepartmentReq) (res *model.DepartmentIdRes, err error) {
	id, _ := service.Department().AddDepartment(ctx, req.DepartmentInfoReq)
	res = &model.DepartmentIdRes{
		Id: id,
	}
	return res, err
}

// EditDepartment  部门修改
func (h *cDepartment) EditDepartment(ctx context.Context, req *api.EditDepartmentReq) (res *model.DepartmentIdRes, err error) {
	id, _ := service.Department().EditDepartment(ctx, req)
	res = &model.DepartmentIdRes{
		Id: id,
	}
	return res, err
}

// DeleteDepartment  删除部门
func (h *cDepartment) DeleteDepartment(ctx context.Context, req *api.DeleteDepartmentReq) (res *model.DepartmentIdRes, err error) {
	id, _ := service.Department().DeleteDepartment(ctx, req)
	var info = &model.DepartmentIdRes{
		Id: id,
	}
	return info, err
}

// BranchDeleteDepartment  批量删除部门
func (h *cDepartment) BranchDeleteDepartment(ctx context.Context, req *api.BatchDeleteDepartmentReq) (res *model.BranchDepartmentIdRes, err error) {
	res, _ = service.Department().BranchDeleteDepartment(ctx, req)
	//var info = &model.DepartmentIdRes{
	//	Id: id,
	//}
	return res, err
}

// DepartmentInfo  获取当前部门的详情
func (h *cDepartment) DepartmentInfo(ctx context.Context, req *api.GetDepartmentReq) (res *api.DepartmentInfoRes, err error) {
	res, _ = service.Department().DepartmentInfo(ctx, req)
	return res, err
}

// DepartmentTree  获取部门树结构
func (h *cDepartment) DepartmentTree(ctx context.Context, req *api.DepartmentTreeReq) (res []*model.DepartmentTreeInfoRes, err error) {
	treeInfo, err := service.Department().DepartmentTree(ctx, req.DepartmentTreeRes)
	_ = gconv.Scan(treeInfo, &res)
	return res, err
}

// DepartmentList  获取部门列表
func (h *cDepartment) DepartmentList(ctx context.Context, req *api.DepartmentListReq) (res *model.DepartmentListRes, err error) {
	res, err = service.Department().DepartmentList(ctx, req.DepartmentListReq)
	return res, err
}
